import { handleCostStatisticsApi } from '@/api/pcs/pcsCostStatistics'
import AekForm from '@/components/AekForm'
import AekModal, { PromiseThen } from '@/components/AekModal'
import { FILE_UPLOAD_TYPE_ENUM } from '@/utils/enum'
import { requestWithTry } from '@/utils/request'

const HandleTransactionModal = ({ row = {} }) => {
  const [form] = AekForm.useForm()

  /** @type {import("@/components/AekForm").FormDataProps[]} */
  const formData = [
    {
      field: 'dealResult',
      label: '处理备注',
      formItemProps: {
        rules: [{ required: true }],
      },
      component: {
        name: 'TextArea',
        props: {
          placeholder: '请输入处理备注',
          maxLength: 600,
          autoSize: { minRows: 6 },
        },
      },
    },
    {
      field: 'qualificationFileList',
      label: '资质证书',
      formItemProps: {
        help: '可上传多个文件，最多5个，支持pdf、png、word、Excel',
      },
      component: {
        name: 'AekUpload',
        props: {
          accept: `png,${FILE_UPLOAD_TYPE_ENUM.PDF},${FILE_UPLOAD_TYPE_ENUM.WORD},${FILE_UPLOAD_TYPE_ENUM.EXECL}`,
          limitFileNum: 5,
        },
      },
    },
  ]

  const onOk = async () => {
    const values = await form.validateFields()
    const params = {
      ...values,
      id: row.id,
      dealFile: values.dealFile?.map(item => ({
        fileUrl: item.url,
        fileName: item.url.split('/').pop(),
      })),
    }
    await requestWithTry(handleCostStatisticsApi, params)
  }

  return (
    <AekModal title='处理' width={500} onOk={onOk}>
      <AekForm form={form} formData={formData} />
    </AekModal>
  )
}

HandleTransactionModal.PromiseThen = PromiseThen

export default HandleTransactionModal
